package digital.store.springmvc.controller;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import digital.store.springmvc.service.CategoryService;
import digital.store.springmvc.service.ProductService;
import digital.store.tutorial.springmvc.model.Category;
import digital.store.tutorial.springmvc.model.Product;

@Controller
@RequestMapping(value="/")
public class HomeController {
	
	@Autowired
	private ProductService productService;
	
	@Autowired
	private CategoryService categoryService;
	
	@RequestMapping(method = RequestMethod.GET)
	 public String list(Model model) {
		
		Collection<Product> products = productService.findAll();
		Collection<Category> categories = categoryService.findAll();
		
	    model.addAttribute("productsList", products);
	    model.addAttribute("categoriesSidebar", categories);
	    return "home";
   }
}
